<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/include/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/include/header.jsp"%>
<!-- 加载树-->
<%@ include file="/include/zTree.jsp"%>
</head>
<body>
	<div class="main_panel">
		<div class="ch_panel" id="queryDiv">
			<input type="hidden" data-qname="currentPage" value="1" />
			<table class="c_table">
				<tr>
					<td>
						<button class="a_btn" id="addBtn">新增</button>
					</td>
					<td width="950px" class="t_l">
						角色名称：
						<input type="text" data-qname="roleName" id="roleName" value="" class="input_txt" style="width: 180px" />
						&nbsp;&nbsp;
					</td>
					<td class="t_r">
						<input type="button" value="查询" id="searchBtn" class="c_btn" />
					</td>
				</tr>
			</table>
		</div>
		<table id="tbwrap" class="table table-border table-bordered table-bg m_t10 hovaertable"></table>
		<div class="page eui-pager-custom" id="j_pager"></div>
	</div>
	<div id="menuContent" class="menuContent" style="display: none; position: absolute; background-color: white;">
		<ul id="treeDemo" class="ztree" style="margin-top: 0; width: 300px;"></ul>
	</div>
	
	
	<%@ include file="/include/footer.jsp"%>
	<script type="text/html" id="tb_template">
		<thead>
			<tr>
				<th width="30%">角色名称</th>
				<th width="20%">状态</th>
				<th width="20%">关联用户</th>
				<th width="30%">操作</th>
			</tr>
		</thead>
		<tbody data-type="body" id="queryTable">
			<!if(list.length>0) { !>
				<!for(var i=0,len=list.length;i<len;i++){
					var item = list[i],classItem = (i%2!=0)?"odd td_odd":"even";
				!>
				<tr class="gradeA <!=classItem!>">
					<td title="<!=item["roleName"]!>"><!=item["roleName"]!></td>
					<td title="<!=item["statusName"]!>"><!=item["statusName"]!></td>
					<td><a title="关联用户" data-value="<!=item["roleId"]!>" class="relevanceUser">查看</a></td>
					<td>
						<a title="设置权限" data-value="<!=item["roleId"]!>" class="setAuthority"style="text-decoration: none;margin-right: 10px;">设置权限</a>

						<a title="详情" data-value="<!=item["roleId"]!>" class="view" style="text-decoration: none;margin-right: 10px;">
							<i class="Hui-iconfont">&#xe665;</i>
						</a>
						<a title="编辑" data-value="<!=item["roleId"]!>" class="edit" style="text-decoration: none;margin-right: 10px;">
							<i class="Hui-iconfont">&#xe6df;</i>
						</a>
						<a title="删除" data-value="<!=item["roleId"]!>" class="delete" style="text-decoration: none">
							<i class="Hui-iconfont">&#xe6e2;</i>
						</a>
					</td>
				</tr>
			<!}!>
			<!}else{!>
				<tr>
					<td colspan="10"> 暂无数据</td>
				</tr>
			<!}!>
		</tbody>
	</script>


	<script type="text/javascript">
		var sysRoleDialog;
		$(function () {
			// 初始化查询
			search();
			
			// 添加
			$("#addBtn").click(function() {
				parent.member_add("添加角色信息", "${ctx}/sysRole/toAdd",800,460);
			});
			
			// 编辑
			$("#tbwrap").delegate(".edit", "click", function() {
				//获取主键
				var roleId = $(this).data("value");
				parent.member_add("编辑角色信息", "${ctx}/sysRole/toEdit?roleId="+roleId,800,460);
				
			});
			
			// 详细
			$("#tbwrap").delegate(".view", "click", function() {
				//获取主键
				var roleId = $(this).data("value");
				parent.member_add("查看角色信息", "${ctx}/sysRole/view?roleId="+roleId,600,300);
				
			});

			//  删除
			$("#tbwrap").delegate(".delete", "click", function () {
				var roleId = $(this).data("value");
				if (confirm('确定删除？')) {
					$.post("${ctx}/sysRole/delete", {
						roleId : roleId, csrfToken : "${csrfToken}"
					}, function (result) {
						if ("succ" == result) {
							alert("操作成功");
							// 刷新列表页面
							search();
						} else {
							alert(result);
						}
					}, "json");
				}

			});
			
			// 查询
			$("#searchBtn").click(function () {
				search();
			});

			// 设置权限
			$("#tbwrap").delegate(".setAuthority", "click", function() {
				//获取主键
				var roleId = $(this).data("value");
				parent.member_add("设置权限", "${ctx}/sysRole/toSetAuthority?roleId="+roleId,850,550);
				
			});

			// 关联用户
			$("#tbwrap").delegate(".relevanceUser", "click", function() {
				//获取主键
				var roleId = $(this).data("value");
				parent.member_add("关联用户", "${ctx}/sysRole/relevanceUser?roleId="+roleId,850,550);
				
			});

		});
	</script>

	<script type="text/javascript">
		function search () {
			// 这里放包含查询条件的DIV
			var paramData = easyUtils.getQueryDivDefault("queryDiv");
			seajs.use([ "component/table" ], function (uiTable) {
				var param = {
					url : "${ctx}/sysRole/ajaxPage", data : paramData
				};
				easyUtils.getData(param, function (result) {
					easyUtils.buildTable(result, param, uiTable);
				});
			});
		}
	</script>
</body>
</html>
